<template>
	<view class="main">
		<guide v-if="guidePages"></guide>
	</view>
</template>

<script>
	import guide from '@/components/guide/guide.vue'
	import Cache from '@/utils/cache'
	export default{
		components: {
		    guide
		},
		data(){
			return {
				guidePages:true//引导页
			}
		},
		onLoad(){
			this.loadExecution()
		},
		methods:{
			loadExecution(){
				/**
				 * 获取本地存储中launchFlag的值
				 * 若存在，说明不是首次启动，直接进入首页；
				 * 若不存在，说明是首次启动，进入引导页；
				 */
				try {
					// 获取本地存储中launchFlag标识
					const value = Cache.get('LAUNCHFLAG');
					if (value) {
						if (Cache.get('TOKEN')) {
							uni.redirectTo({
								url: '/pages/home/home'
							});
						} else {
							uni.redirectTo({
								url: '/pages/login/index'
							});
						}
					} else {
						this.guidePages = true
					}
				} catch(e) { 
					// error 
					Cache.set("LAUNCHFLAG", true, 59 * 24 * 60 * 60);
					this.guidePages = true
				}
			}
		}
	}
</script>

<style>
	page,.main{
		width: 100%;
		height: 100%;
		background: #FFFFFF;
		position: relative;
		z-index: 220000;
	}
</style>